package nbcp.base.extend


/**
 * 按数字分隔，返回数字和非数字各部分
 */
fun Regex.splitBoundary(value: String): Array<String> {
    var ret = mutableListOf<String>()

    var prevIndex = 0;
    this.findAll(value).forEachIndexed { index, matchResult ->
        if (prevIndex != matchResult.range.first) {
            ret.add(value.substring(prevIndex, matchResult.range.first))
        }
        ret.add(matchResult.value)

        prevIndex = matchResult.range.last + 1;
    }

    if (prevIndex != value.length) {
        ret.add(value.substring(prevIndex))
    }
    return ret.filter { it.HasValue }.toTypedArray();
}
